import * as path from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import pkg from './package.json';

process.env.VITE_APP_VERSION = pkg.version;
if (process.env.NODE_ENV === 'production') {
	process.env.VITE_APP_BUILD_EPOCH = new Date().getTime().toString();
}

export default defineConfig(({ command }) => {
	console.log('command===>', command);
	return {
		plugins: [
			vue({
				script: {
					refSugar: true,
				},
			}),
		],
		resolve: {
			alias: {
				'@': path.resolve(__dirname, './src'),
			},
		},
		build: {
			minify: 'terser', // 默认为 Esbuild，它比 terser 快 20-40 倍，压缩率只差 1%-2%，出于使用drop_console，故选用terser
			terserOptions: {
				/**
				 * command 用来判断环境
				 */
				compress: {
					drop_console: command !== 'serve',
					// 默认是true
					drop_debugger: command !== 'serve',
				},
			},
		},
	};
});
